package com.whynot.frame.stream.mq.send;

import com.whynot.frame.stream.mq.config.MessageMQ;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 描    述:发消息到mq
 * 创建时间: 2018/12/20
 */
@Service
@EnableBinding(MessageMQ.class)
public class MessageSendMQ {
    @Autowired
    @Output(MessageMQ.WECHAT_SEND_OUTPUT)
    MessageChannel sendMsgMQ;

    @Autowired
    @Output(MessageMQ.WECHAT_RECEIVE_OUTPUT)
    MessageChannel receiveMsgMQ;

    public void sendMsg (Map<String, Object> msg){
        sendMsgMQ.send(MessageBuilder.withPayload(msg).build());
    }

    public void receiveMsg (Map<String, Object> msg){
        receiveMsgMQ.send(MessageBuilder.withPayload(msg).build());
    }
}